package com.dlc.felear.xiaoensale.activity;

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.dlc.felear.xiaoensale.R;
import com.dlc.felear.xiaoensale.constant.Constant;
import com.dlc.felear.xiaoensale.dao.MenuTypeDao;
import com.dlc.felear.xiaoensale.entity.MenuType;
import com.itdlc.android.library.base.BaseActivity;
import com.itdlc.android.library.utils.APPDidUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 炒菜机器人主页
 */
public class CcLauncherActivity extends BaseActivity  {
    private static final String TAG = "CcLauncherActivity";
    @BindView(R.id.first_tv_version)
    TextView tv;


    @Override
    protected int getLayoutRes() {
        return R.layout.activity_cc_launcher;
    }

    @Override
    protected void initData() {
        String appId = APPDidUtil.getAppDid();
        int length = appId.length();
        tv.setText("编码：" + appId.substring(length - 4, length));
    }

    @OnClick({R.id.f_ll_cc, R.id.f_ll_sz, R.id.f_ll_sdcz, R.id.f_ll_cpk, R.id.f_ll_cpbz, R.id.iv_clock, R.id.f_ll_gdcp})
    public void onItemClick(View view) {
        Log.e(TAG, "点击事件");
        switch (view.getId()) {
            case R.id.f_ll_sz:
                startActivity(new Intent(this, ParamerSettingActivity.class));
                break;
            case R.id.f_ll_sdcz:
                startActivity(new Intent(this, ManualDebugActivity.class));
                break;
            case R.id.f_ll_cpbz:
                startActivity(new Intent(this, EditMenuActivity.class));
                break;
            case R.id.f_ll_cpk:
                startActivity(new Intent(this, MenuListActivity.class));
                break;
            case R.id.f_ll_cc:
                startActivity(new Intent(this, CookingMenuActivity.class));
                break;
            case R.id.iv_clock:
                startActivity(new Intent(this, FirstActivity.class));
                break;
            case R.id.f_ll_gdcp:
                startActivity(new Intent(this, GdCookingMenuActivity.class));
                break;
        }
    }



    private void jumpEditMenu( String id) {
        Intent intent = new Intent(this, EditMenuActivity.class);
        intent.putExtra("mainFoodId", id);
        startActivity(intent);
    }

    private void shouSelectDialog() {
        MenuTypeDao menuTypeDao=new MenuTypeDao(this);
        List<MenuType> data=menuTypeDao.queryForAll();
        if(data==null||data.isEmpty()){
            jumpEditMenu("");
            return;
        }
        Intent intent = new Intent(this, MenuFlavourTypeListActivity.class);
        intent.putExtra("src", 1);
        startActivityForResult(intent, MenuFlavourTypeListActivity.CODE);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
        try {
            if (requestCode == 1024) {
                String value2 = intent.getStringExtra(Constant.OPERATOR_VALUE_2);
                jumpEditMenu(value2);
            }
        } catch (Exception e) {
            showShortToast("数据异常");
        }
    }
}
